﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Easy_374_GuessNumber
{
    class MainProject
    {
        public static int guess = 1702766719;
        static void Main(string[] args)
        {
            Console.WriteLine(GuessNumber(2126753390));
            Console.ReadKey();
        }
        public static int GuessNumber(int n)
        {
            long res = 2;
            long ge = n / 2;
            long last = n;
            long first = 1;
            while (res != 0)
            {
                res = Guess((int)ge);
                if (res == -1)
                {
                    last = ge;
                    ge = (first + ge) / 2;
                }
                if (res == 1)
                {
                    first = ge;
                    ge = (last + ge + 1) / 2;
                }
            }
            return (int)ge;
        }
        public static int Guess(int n)
        {
            if (n>guess)
            {
                return -1;
            }
            if (n < guess)
            {
                return 1;
            }
            return 0;
        }
    }
}
